package com.zx.mes.disruptor.hyl.heigh;

import com.lmax.disruptor.dsl.Disruptor;

import java.util.UUID;
import java.util.concurrent.CountDownLatch;

/**
 * 向disruptor(实际上是向ringBuffer中投数据)
 *
 * @author huayunlong
 * @date 2018-9-7
 */
public class PublishTradeEvent implements Runnable {

    private CountDownLatch countDownLatch;

    private Disruptor<TradeEvent> disruptor;

    public PublishTradeEvent(CountDownLatch countDownLatch, Disruptor<TradeEvent> disruptor) {
        this.countDownLatch = countDownLatch;
        this.disruptor = disruptor;
    }

    @Override
    public void run() {
        this.disruptor.publishEvent((event, sequence)->{
            event.setId(UUID.randomUUID().toString());
            this.countDownLatch.countDown();
        });
    }
}
